import java.util.Scanner;

public class BankSysView {
	Scanner s;

	// constructor for the bank view class
	BankSysView() {
		s = new Scanner(System.in);
	}

	public void clearConsole(){
		for(int i=0;i<35;i++){
			System.out.println("\n");
		}
	}
	public String getUserName() {
		System.out.println("Please enter username");
		return s.next();
	}

	public String getPassword() {
		System.out.println("Please enter password");
		return s.next();
	}

	//displays the menu to select an account to manage
	public BankAccount displayAvailableAccountsMenu(BankAccount[] accounts){
		int selection=Integer.MAX_VALUE;
		boolean inMenu=true;
		while (inMenu) {
			int i=0;
			for(i=0;i<accounts.length;i++){
				System.out.println(i+1+") "+accounts[i].getAccountNum());
			}
			System.out.println(i+1+") Exit");
			selection=s.nextInt();
			//Check for invalid entries
			if (selection > accounts.length+1) {
				System.out.println("Invalid selection please try again");
				this.clearConsole();
			} 
			else
				inMenu = false;
		}
		if(selection==accounts.length+1){
			return null;
		}
		else
			return accounts[selection-1];
	}
	
	// displays account menu and returns chosen selection
	public int displayAccountMenu(int permissions,int accountNumber, String ownerName, String accountNickName, int ownerID, int type,double balance, double interestRate) {
		int selection=0;
		boolean inMenu = true;
		switch (permissions) {

		// Administrator
		case 1:
			while (inMenu) {
				System.out.println("Account Number: "+accountNumber);
				System.out.println("Owner Name: "+ownerName);
				System.out.println("Please select an option:");
				System.out.println("1) Make a deposit");
				System.out.println("2) Withdraw funds");
				
				if(type==2){
					System.out.println("3) Adjust interest rate");
					System.out.println("4) Accure interest");
					System.out.println("5) Back");
				}
				
				else
					System.out.println("3) Back");
				selection = s.nextInt();
				
				//Check for invalid entries
				if(type==2){
					if (selection < 1 || selection > 5) {
						System.out.println("Invalid selection please try again");
						this.clearConsole();
					} 
					else
						inMenu = false;
				}
				else
				{
					
					if (selection < 1 || selection > 3) {
						System.out.println("Invalid selection please try again");
						this.clearConsole();
					} 
					else{
							if(selection==3){
								//Add 2 to selection to accurately break loop for the menu
								selection+=2;
							}
						inMenu = false;
					}
				}
			}
			break;
		}
		return selection;
	}

	//Prompts for the amount to deposit
	public double getDepositAmount(){
		System.out.println("Please enter the amount to deposit: ");
		return s.nextDouble();
	}
	
	//Prompts for the amount to withdraw
	public double getWithdrawAmount(){
		System.out.println("Please enter the amount to withdraw: ");
		return s.nextDouble();
	}
	
	//Prompts for the new interest rate
	public double getNewInterestRate(){
		System.out.println("Please enter the adjusted interest rate: ");
		return s.nextDouble();
	}
	
	//used to display the interest rate to the user after adjusting it
	public void notifyInterestRate(double IR){
		System.out.println("The intrest rate has been set to: "+IR);
	}
	
	//notifies user that the interest has been added to the account
	public void notifyInterestGain(){
		System.out.println("The intrest has been applied to the account");
	}
	
	//displays the balance for an account
	public void displayBalance(double balance){
		System.out.println("\nBalance: "+balance+"\n");
	}
	
	//prints out an error or confirming message
	public void printMessage(String msg){
		System.out.println("\n"+msg+"\n");
	}
}
